class Solution(object):
    def splitLoopedString(self, strs):
        """
        :type strs: List[str]
        :rtype: str
        """
        max_c= 'a'
        max_str = ''.join(strs)
        for i in range(len(strs)):
            for c in strs[i]:
                max_c = max(c, max_c)
            re = strs[i][::-1]
            if re > strs[i]:
                strs[i] = re
        for i in range(len(strs)):
            if max_c in strs[i]:
                strs[i] = strs[i][::-1]
                for j in range(len(strs[i])):
                    if strs[i][j] == max_c:
                        new_str = [strs[i][j:]] + strs[i + 1:] + strs[:i] + [strs[i][:j]]
                        max_str = max(max_str, ''.join(new_str))
                strs[i] = strs[i][::-1]
                for j in range(len(strs[i])):
                    if strs[i][j] == max_c:
                        new_str = [strs[i][j:]] + strs[i + 1:] + strs[:i] + [strs[i][:j]]
                        max_str = max(max_str, ''.join(new_str))
        return max_str

data = Solution()
strs = ["abc", "xyz"]
print(data.splitLoopedString(strs))
strs = ["abc", "xyz", "zzx"]
print(data.splitLoopedString(strs))